package com.playball.lottery.fragment.frm;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.R;
import com.playball.lottery.adapter.BarberGalleryAdapter;
import com.playball.lottery.adapter.GridViewAdapter;
import com.playball.lottery.bean.APPOfAdvertisingBean;
import com.playball.lottery.bean.Tab1Bean;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.BarberGallery;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.eventmanger.EventManager;
import com.playball.lottery.eventmanger.EventType;
import com.playball.lottery.frm.buyhall.BDActivity;
import com.playball.lottery.frm.buyhall.CQSSCActivity;
import com.playball.lottery.frm.buyhall.CQSSCListActivity;
import com.playball.lottery.frm.buyhall.CtzqBqcActivity;
import com.playball.lottery.frm.buyhall.CtzqJqcActivity;
import com.playball.lottery.frm.buyhall.CtzqRx9Activity;
import com.playball.lottery.frm.buyhall.CtzqSfcActivity;
import com.playball.lottery.frm.buyhall.DltxhActivity;
import com.playball.lottery.frm.buyhall.DltxhlbActivity;
import com.playball.lottery.frm.buyhall.ElvSelFiveActivity;
import com.playball.lottery.frm.buyhall.ElvSelFiveListActivity;
import com.playball.lottery.frm.buyhall.ElvYunDJActivity;
import com.playball.lottery.frm.buyhall.ElvYunDJListActivity;
import com.playball.lottery.frm.buyhall.Fc3dListActivity;
import com.playball.lottery.frm.buyhall.Fc3dxhActivity;
import com.playball.lottery.frm.buyhall.JcBasketballActivity;
import com.playball.lottery.frm.buyhall.JcfootballActivity;
import com.playball.lottery.frm.buyhall.Kuai3Activity;
import com.playball.lottery.frm.buyhall.Kuai3ListActivity;
import com.playball.lottery.frm.buyhall.N7lxhActivity;
import com.playball.lottery.frm.buyhall.N7lxhlbActivity;
import com.playball.lottery.frm.buyhall.N7xxhActivity;
import com.playball.lottery.frm.buyhall.N7xxhlbActivity;
import com.playball.lottery.frm.buyhall.Pailie3ListActivity;
import com.playball.lottery.frm.buyhall.Pailie3xhActivity;
import com.playball.lottery.frm.buyhall.Pailie5ListActivity;
import com.playball.lottery.frm.buyhall.Pailie5xhActivity;
import com.playball.lottery.frm.buyhall.SixFuckActivity;
import com.playball.lottery.frm.buyhall.SsqxhActivity;
import com.playball.lottery.frm.buyhall.SsqxhlbActivity;
import com.playball.lottery.nt.animal.O2OServiceImpl;
import com.playball.lottery.sessions.SessionManager;
import com.playball.lottery.util.AbstractActivity;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.LotConstants;
import com.playball.lottery.util.OKHttpConstants;
import com.playball.lottery.util.PreferencesUtils;
import com.playball.lottery.util.province.GlobalUtils;
import com.playball.lottery.widget.HomeGridView;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.playball.lottery.JddMainActivity.USERID;


public class Tab1Fragment extends Fragment implements LotConstants, View.OnClickListener {
    public static final String TAG = "Tab1Fragment";
    public static String mUrl;
    private BarberGallery headerGallery;
    private PreferencesUtils pUtil;
    private View _RootView;
    private LinearLayout indicatorLL;
    private int positon;
    private TextView top_title_info;
    private ImageView top_title_back;
    public O2OServiceImpl o2OService;
    private HomeGridView gv;
    private LinearLayout line_goBuy;
    private TextView tv_more;
    private TextView tv_forward_lottery;
    private  ShowTipDialog showdialog;
    // Session Manager Class
    private SessionManager session;

    private Map<String, String> userDetails;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pUtil = new PreferencesUtils(getActivity(), Constants.PREFERENCES_NAME);

        o2OService = new O2OServiceImpl();
        // Session Manager
        session = new SessionManager(getActivity().getApplicationContext());
        USERID=session.getUserIDs();
        if (session.isLoggedIn()) {
            userDetails = session.getUserDetails();
        } else {
            userDetails = new HashMap<>();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        _RootView = inflater.inflate(R.layout.fragment_tab1, null);

        return _RootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        initTitle();  //初始化标题
        initView(); //初始化控件

         showdialog = new ShowTipDialog();
        showdialog.showDialog(getActivity());
         if(AbstractActivity.isNetworkAvailable(getActivity())==true){
             if(showdialog!=null){
                 showdialog.closeDialog();
             }
            getAdvertisingData();

            getLotteriesAfterLogin();
        }

    }


    @Override
    public void onResume() {
        super.onResume();
        if(AbstractActivity.isNetworkAvailable(getActivity())==true){
            if(showdialog!=null){
                showdialog.closeDialog();
            }
            getAdvertisingData();
            getLotteriesAfterLogin();
        }else{
        showdialog.showDialog(getActivity());
 }

    }

    //初始化标题
    private void initTitle() {
        top_title_back = (ImageView) _RootView.findViewById(R.id.top_title_back);
        top_title_info = (TextView) _RootView.findViewById(R.id.top_title_info);

    }

    //初始化控件
    private void initView() {
        //广告位
        headerGallery = (BarberGallery) _RootView.findViewById(R.id.headerGallery);
        //点击查看更多
        tv_more = (TextView) _RootView.findViewById(R.id.tv_more);
        tv_more.setOnClickListener(this);
        //前往购买大厅
        line_goBuy = (LinearLayout) _RootView.findViewById(R.id.line_goBuy);
        line_goBuy.setOnClickListener(this);

        gv = (HomeGridView) _RootView.findViewById(R.id.gv_tab1);

        // 前往开奖大厅
//        tv_forward_lottery = (TextView) _RootView.findViewById(R.id.tv_forward_lottery);
//        tv_forward_lottery.setOnClickListener(this);
    }

    //广告位
    private void initActivity(final List<APPOfAdvertisingBean> list) {

        if (list == null || list.size() == 0) {
            return;
        }

        headerGallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                changePointView(position % list.size());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        indicatorLL = (LinearLayout) _RootView.findViewById(R.id.indicatorLLId);
        indicatorLL.removeAllViews();
        float density = GlobalUtils.getDensity(getActivity());
        for (int i = 0; i < list.size(); i++) {
            ImageView pointView = new ImageView(getActivity());
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins((int) density * 10, 0, 0, 0);
            pointView.setLayoutParams(layoutParams);
            if (i == 0) {
                pointView.setBackgroundResource(R.drawable.indicator_point_pressed);
            } else
                pointView.setBackgroundResource(R.drawable.indicator_point_normal);
            indicatorLL.addView(pointView);
        }
        BarberGalleryAdapter adapter = new BarberGalleryAdapter(getActivity(), list, headerGallery);
        headerGallery.setAdapter(adapter);
    }


    /**
     * point选择切换
     *
     * @param cur
     */
    private void changePointView(int cur) {
        View view = indicatorLL.getChildAt(positon);
        View curView = indicatorLL.getChildAt(cur);
        if (view != null && curView != null) {
            ImageView pointView = (ImageView) view;
            ImageView curPointView = (ImageView) curView;
            pointView.setBackgroundResource(R.drawable.indicator_point_normal);
            curPointView.setBackgroundResource(R.drawable.indicator_point_pressed);
            positon = cur;
        }
    }

    /**
     * 点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //点击查看更多
            case R.id.tv_more:
                break;
            //前往购买大厅
            case R.id.line_goBuy:
                break;
            //前往开奖大厅
            /*case R.id.tv_forward_lottery:
                ((JddMainActivity)getActivity()).refreshForwardLottery();
                break;*/
            default:
                break;
        }
    }

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    OkHttpClient client = new OkHttpClient().newBuilder()
            .connectTimeout(OKHttpConstants.CONNECT_TIMEOUT, TimeUnit.SECONDS)
            .build();

    Call post(String url, String json, Callback callback) {
        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();
        Call call = client.newCall(request);
        call.enqueue(callback);
        return call;
    }

    /**
     * 获取九宫格的彩种
     */
    public void getLotteriesAfterLogin() {
        System.out.println("**" + userDetails.get(session.KEY_USERID));
        String url = o2OService.getURLOfLotteriesAfterLogin(userDetails.get(session.KEY_USERID));
        Log.v("++++++++Tab1Fragment",url);
        post(url, "", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String responseStr = response.body().string();
                    String str = responseStr.replaceAll("<a>\\s*|\t|\r|\n</a>", "").trim();
                    Log.v("++++++++Tab1Fragment",responseStr);
                    if (str != null) {
                        try {
                            JSONTokener jsonParser = new JSONTokener(str);
                            JSONObject js = (JSONObject) jsonParser.nextValue();
                            final Map<String, Object> Data = com.playball.lottery.util.ConvertJsonToList.getMap(js.getString("Data"));
                            if (Data != null) {
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {

                                        top_title_info.setText(Data.get("Title").toString());
                                        String Lotteries = Data.get("Lotteries").toString();
                                        String mJiaJiang=Data.get("JiaJiang").toString();
                                        mUrl=Data.get("Url").toString();
                                        if ("".equals(mUrl)){
                                            mUrl="dd.tcaio2o.com";
                                        }
                                        if (!"null".equals(Data.get("Logo").toString())){
                                            ImageLoader.getInstance().displayImage(Data.get("Logo").toString(), top_title_back, GlobalUtils.getDisplayImageOptions());
                                        }
                                        session.createLSIDSession(Data.get("LSID").toString());
                                        final String[] strang=mJiaJiang.split(",");
                                        final String[] strArray = Lotteries.replace("[", "").replace("]", "").split(",");

//                                   Toast.makeText(getActivity(),strArray.length+"****"+strArray[0],Toast.LENGTH_LONG).show();
                                        if (strArray.length < 9) {
                                            tv_more.setVisibility(_RootView.GONE);
                                            if (strArray.length < 3) {
                                                ViewGroup.LayoutParams params = gv.getLayoutParams();
                                                int w = GlobalUtils.getWidthPixels(getActivity());
                                                int h = (int) (w * 0.23);
                                                params.height = h;
                                                gv.setLayoutParams(params);
                                            } else if (strArray.length > 3 && strArray.length < 6) {
                                                ViewGroup.LayoutParams params = gv.getLayoutParams();
                                                int w = GlobalUtils.getWidthPixels(getActivity());
                                                int h = (int) (w * 0.44);
                                                params.height = h;
                                                gv.setLayoutParams(params);
                                            } else if (strArray.length > 6 && strArray.length < 9) {
                                                ViewGroup.LayoutParams params = gv.getLayoutParams();
                                                int w = GlobalUtils.getWidthPixels(getActivity());
                                                int h = (int) (w * 0.68);
                                                params.height = h;
                                                gv.setLayoutParams(params);
                                            }
                                        } else {
                                            tv_more.setVisibility(_RootView.GONE);
                                            ViewGroup.LayoutParams params = gv.getLayoutParams();
                                            int w = GlobalUtils.getWidthPixels(getActivity());
                                            int h = (int) (w * 0.68);
                                            params.height = h;
                                            gv.setLayoutParams(params);
                                        }
                                        if(strArray[0]==""){
                                            return;
                                        }
                                        GridViewAdapter ad = new GridViewAdapter(getActivity(), strArray,strang);
                                        gv.setAdapter(ad);
                                        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                            @Override
                                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                                String str = strArray[position].replace("[", "").replace("]", "");
                                                str = str.substring(1, str.length() - 1);
                                                int ilotId = Integer.valueOf(str);
                                                go(position,ilotId);
                                            }
                                        });
                                    }
                                });
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                } else {
                    // Request not successful
                    throw new IOException("Unexpected code " + response);
                }
            }
        });
    }

    public void go(int position, int ilotId) {
//        Map<String, Object> item = (Map<String, Object>) gv.getAdapter().getItem(position);
        Intent intent = new Intent();
        switch (ilotId) {
            case LOT_ID_LHC://六合彩ID
                intent.setClass(getActivity(), SixFuckActivity.class);
                break;
            case LOT_ID_SSQ://双色球ID
                int ssq_size = pUtil.getInt("ssq_size", 0);
                if (ssq_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < ssq_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setSsq_ball(pUtil.getString("ssq_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_ssqdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("ssq_allMoney", 0));
                    intent.setClass(getActivity(), SsqxhlbActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), SsqxhActivity.class);
                }
                break;
            case LOT_ID_DLT://大乐透ID
                int dlt_size = pUtil.getInt("dlt_size", 0);
                if (dlt_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < dlt_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setDlt_ball(pUtil.getString("dlt_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_dltdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("dlt_allMoney", 0));
                    intent.setClass(getActivity(), DltxhlbActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), DltxhActivity.class);
                }
                ApplicationData.getInstance().setIsDLTZhuiJiaClick(false);
                break;
            case LOT_ID_11X5://11选5
                int esf_size = pUtil.getInt("esf_size", 0);
                if (esf_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < esf_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setElv_ball(pUtil.getString("esf_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("esf_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("esf_play", 0));
                    intent.putExtra("prizeIntellChase", pUtil.getInt("esf_prizeIntellChase", 0));
                    intent.setClass(getActivity(), ElvSelFiveListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), ElvSelFiveActivity.class);
                }
                break;
            case LOT_ID_JCZQ://竞彩足球
                intent.setClass(getActivity(), JcfootballActivity.class);
                break;
            case LOT_ID_BD://北京单场 ID
                intent.setClass(getActivity(), BDActivity.class);
                break;
            case LOT_ID_JCLQ://竞彩篮球
                intent.setClass(getActivity(), JcBasketballActivity.class);
                break;
            case LOT_ID_ZQ_SFC://胜负彩ID
                intent.setClass(getActivity(), CtzqSfcActivity.class);
                break;
            case LOT_ID_ZQ_RX9://任选9 ID
                intent.setClass(getActivity(), CtzqRx9Activity.class);
                break;
            case LOT_ID_JQC://进球彩
                intent.setClass(getActivity(), CtzqJqcActivity.class);
                break;
            case LOT_ID_BQC://半全场
                intent.setClass(getActivity(), CtzqBqcActivity.class);
                break;
            case LOT_ID_FC3D://福彩 3D
                int fc3d_size = pUtil.getInt("fc3d_size", 0);
                if (fc3d_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < fc3d_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setPl3_ball(pUtil.getString("fc3d_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("fc3d_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("fc3d_play", 0));
                    intent.setClass(getActivity(), Fc3dListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), Fc3dxhActivity.class);
                }
                break;
            case LOT_ID_QLC:// 七乐彩 ID
                int n7lx_size = pUtil.getInt("n7lx_size", 0);
                if (n7lx_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < n7lx_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setPl3_ball(pUtil.getString("n7lx_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("n7lx_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("n7lx_play", 0));
                    intent.setClass(getActivity(), N7lxhlbActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), N7lxhActivity.class);
                }
                break;
            case LOT_ID_PL3://排列3 ID
                int pl3_size = pUtil.getInt("pl3_size", 0);
                if (pl3_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < pl3_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setPl3_ball(pUtil.getString("pl3_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("pl3_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("pl3_play", 0));
                    intent.setClass(getActivity(), Pailie3ListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), Pailie3xhActivity.class);
                }
                break;
            case LOT_ID_PL5://排列5 ID
                int pl5_size = pUtil.getInt("pl5_size", 0);
                if (pl5_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < pl5_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setPl5_ball(pUtil.getString("pl5_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("pl5_allMoney", 0));
                    intent.setClass(getActivity(), Pailie5ListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), Pailie5xhActivity.class);
                }
                break;
            case LOT_ID_QXC://七星彩 ID
                int n7xx_size = pUtil.getInt("n7xx_size", 0);
                if (n7xx_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < n7xx_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setPl3_ball(pUtil.getString("n7xx_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("n7xx_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("n7xx_play", 0));
                    intent.setClass(getActivity(), N7xxhlbActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), N7xxhActivity.class);
                }
                break;
            case LOT_ID_CQSSC://重庆时时彩
                int cqssc_size = pUtil.getInt("cqssc_size", 0);
                if (cqssc_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < cqssc_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setElv_ball(pUtil.getString("cqssc_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("cqssc_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("cqssc_play", 0));
                    intent.putExtra("strPlayType", pUtil.getString("cqssc_type", ""));
                    intent.putExtra("prizeIntellChase", pUtil.getInt("cqssc_prizeIntellChase", 0));
                    intent.setClass(getActivity(), CQSSCListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), CQSSCActivity.class);
                }
                break;
            case LOT_ID_11YDJ://11运夺金
                int eydu_size = pUtil.getInt("eydu_size", 0);
                if (eydu_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < eydu_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setElv_ball(pUtil.getString("eydu_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("eydu_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("eydu_play", 0));
                    intent.putExtra("prizeIntellChase", pUtil.getInt("eydu_prizeIntellChase", 0));
                    intent.setClass(getActivity(), ElvYunDJListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), ElvYunDJActivity.class);
                }
                break;
            case LOT_ID_KUAI3://快三
                int kuai3_size = pUtil.getInt("kuai3_size", 0);
                if (kuai3_size != 0) {
                    ArrayList<BallDTO> list = new ArrayList<BallDTO>();
                    for (int i = 0; i < kuai3_size; i++) {
                        BallDTO ball = new BallDTO();
                        ball.setElv_ball(pUtil.getString("kuai3_ball" + i, ""));
                        list.add(ball);
                    }
                    intent.putExtra("list_elvdto", list);
                    intent.putExtra("AllMoney", pUtil.getInt("kuai3_allMoney", 0));
                    intent.putExtra("PlayTypeID", pUtil.getInt("kuai3_play", 0));
                    intent.putExtra("prizeIntellChase", pUtil.getInt("kuai3_prize", 0));
                    intent.setClass(getActivity(), Kuai3ListActivity.class);
                    Toast.makeText(getActivity(), R.string.this_is_the_last_time_you_save_the_number, Toast.LENGTH_SHORT).show();
                } else {
                    intent.setClass(getActivity(), Kuai3Activity.class);
                }
                break;
        }
//        getActivity().startActivityForResult(intent, REQ_BUYLOT_FROM_MAINHOME);
        getActivity().startActivity(intent);
    }





    /**
     * 获取广告位数据
     */
    public void getAdvertisingData() {
        final ArrayList<APPOfAdvertisingBean> list = new ArrayList<APPOfAdvertisingBean>();

//        String url = o2OService.getURLOfAdvertising2();
        String url = "http://mobile.tcaio2o.com/MobileHandler.ashx?platformVersion=6.0&UserID=ODMw&platformCode=Android&sign=6AC3583C15FEB7B931172E8E6AF71937&appVersion=1.0&cmdName=app_zz&uuid="+userDetails.get(session.KEY_USERID)+"&action=23&params={\"LSID\":\"3\"}";
        post(url, "", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String responseStr = response.body().string();
                    String str = responseStr.replaceAll("<a>\\s*|\t|\r|\n</a>", "").trim();
                    // Do what you want to do with the response.
//                    System.out.println(responseStr);
                    if (str != null) {
                        try {
                            JSONTokener jsonParser = new JSONTokener(str);
                            JSONObject js = (JSONObject) jsonParser.nextValue();
                            List<Map<String, Object>> Data = com.playball.lottery.util.ConvertJsonToList.getList(js.getString("Data"));
                            if (Data != null) {
                                for (int i = 0; i < Data.size(); i++) {
                                    APPOfAdvertisingBean bean = new APPOfAdvertisingBean();
                                    bean.setTitle(Data.get(i).get("Title").toString());
                                    bean.setLinkUrl(Data.get(i).get("LinkUrl").toString());
                                    bean.setImgPath(Data.get(i).get("ImgPath").toString());
                                    bean.setCreateTime(Data.get(i).get("CreateTime").toString());
                                    bean.setTypeID(Data.get(i).get("TypeID").toString());
                                    list.add(bean);
                                }

                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (list != null) {
                                            initActivity(list);

                                        }
                                    }
                                });
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    // Request not successful
                    throw new IOException("Unexpected code " + response);
                }
            }
        });
    }


}
